package cool.taomu.toolkit.micrometer.service

import javax.inject.Inject
import io.micrometer.core.instrument.MeterRegistry
import org.eclipse.xtend.lib.annotations.Accessors
import java.util.Map
import java.util.HashMap

@Accessors
class MeterRegistryService {
	@Inject
	MeterRegistry meterRegistry;

	def metrics() {
		val Map<String, Object> metricsMap = new HashMap();

		// 将指标数据转化为键值对
		meterRegistry.getMeters().forEach([ meter |
			val String metricName = meter.getId().getName();
			meter.measure().forEach([ measurement |
				var String key = metricName + "_" + measurement.getStatistic().toString().toLowerCase();
				metricsMap.put(key, measurement.getValue());
			]);
		]);
		return metricsMap
	}

}
